/*
 * DShowGraph.h
 *
 *  Created on: 2011-8-5
 *      Author: terry
 */

#ifndef DSHOWGRAPH_H_
#define DSHOWGRAPH_H_

#include "MediaStream.h"
#include "DShowType.h"

#include "SampleCallBack.h"
#include "SampleGrabberCallback.h"
#include <atlbase.h>

typedef CComPtr< IBaseFilter >      IBaseFilterPtr;
typedef CComPtr< IPin >             IPinPtr;
typedef CComPtr< IVideoWindow >     IVideoWindowPtr;
typedef CComPtr< IGraphBuilder >    IGraphBuilderPtr;
typedef CComPtr< IMediaControl >    IMediaControlPtr;
typedef CComPtr< IAMStreamConfig >  IAMStreamConfigPtr;


class DShowGraph
{
public:
	DShowGraph();
	virtual ~DShowGraph();

	virtual HRESULT initGraph();

	virtual HRESULT playGraph();
	virtual HRESULT pauseGraph();
	virtual HRESULT stopGraph();

	virtual void uninitGraph();

	virtual HRESULT buildGraph() =0;
    virtual void destroyGraph() =0;
    virtual int queryMediaFormat(av::MediaFormat& fmt) =0;

    virtual ISampleGrabber* getVideoGrabber() =0;
    virtual ISampleGrabber* getAudioGrabber() =0;

    void setSampleCallBack(av::SampleCallBack* pCB);


    int querySampleMediaFormat(ISampleGrabber* pGrabber, av::MediaFormat& fmt);

	void freeMediaType(AM_MEDIA_TYPE* pType);

	bool supportMediaSubType(const GUID& guid);

	int mediaSubTypeToColorSpace(const GUID& guid);

    HRESULT removeFilter(IBaseFilter* pFilter);
    void removeAllFilters();
    

    bool isValid() const;

    HRESULT addFilter(IBaseFilter* pFilter, LPCWSTR wszName);

    HRESULT addFilter(const CLSID clsid, LPCWSTR wszAlias, IBaseFilter** ppFilter);

    FILTER_STATE getGraphState();

    HRESULT findFilterByName(LPCWSTR wszName,IBaseFilter** ppFilter);

    HRESULT showVideoWnd(bool show);

    IVideoWindow* queryVideoWindow();



public:
	DWORD		m_rotCookie;
    IGraphBuilder*  m_graphBuilder;
    IMediaControl*	m_mediaControl;

    ICaptureGraphBuilder2*	m_captureBuilder2;


protected:
    av::SampleCallBack* m_pSampleCallBack;

};

#endif /* DSHOWGRAPH_H_ */
